package com.cuteboy.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class ValidateUtils {
    public ValidateUtils() {
    }

    public static boolean isNull(Object s) {
        return s == null;
    }

    public static boolean isNotNull(Object s) {
        return s != null;
    }

    public static boolean isNull(String s) {
        return s == null;
    }

    public static boolean isNotNull(String s) {
        return s != null;
    }

    public static boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }

    public static boolean isEmpty(Collection<?> c) {
        return c == null || c.size() == 0;
    }

    public static boolean isNotEmpty(String s) {
        return s != null && s.length() > 0;
    }

    public static boolean isNotEmpty(Collection<?> c) {
        return c != null && c.size() > 0;
    }

    public static boolean isString(Object obj) {
        return obj != null && obj instanceof String;
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return map != null && map.size() > 0;
    }


    public static boolean isEmpty(String[] s) {
        return s == null || s.length == 0;
    }

    public static boolean isNotEmpty(String[] s) {
        return s != null && s.length > 0;
    }

    public static boolean isTrimEmpty(String s) {
        return s == null || s.trim().length() == 0;
    }

    public static boolean isEmail(String email) {
        return email != null && email.matches("(\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)");
    }

    public static boolean isUrl(String url) {
        return url != null && url.matches("(http|ftp|https)://[\\w\\-_]+(\\.[\\w-_]+)+([\\w-.,@?^=%&amp;:/~+#]*[\\w-@?^=%&amp;/~+#])?");
    }

    public static boolean isPUrl(String url) {
        return url != null && url.matches("((http|ftp|https)://)([a-zA-Z0-9_-]+\\.)*");
    }

    public static boolean isEmptyArray(Object array) {
        return array == null?true:(array.getClass().isArray()?Array.getLength(array) == 0:false);
    }
    
    public static boolean isMobile(String mobiles) {
        Pattern p = Pattern.compile("^1(3|5|7|8|4)\\d{9}");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }
    
    public static boolean isBankCard(String str) {
        //一般银行卡是16位到19为，但是有些公司卡是15位的，好像也有13位的这里直接通过
        return str.matches("^\\d{13}|\\d{15}|\\d{16}|\\d{17}|\\d{18}|\\d{19}$");
    }
    
}
